import React, { useReducer, useEffect } from 'react'
import { initState, reducer, actions } from "./register.js"
import { reqRegister } from "../../request/api";
import "./register.css"

export default function Register() {
    const [state, dispatch] = useReducer(reducer, initState);
    //相当于生命周期
    useEffect(() => {

    }, []);
    let req = ()=>{
        reqRegister(state.user)
    }
    return (
        <div>
            <div className="register">
                <h2>注册</h2>
                <div className="main">
                    <div>手机号<input type="text" value={state.user.phone} onChange={(e) => dispatch(actions.changeUser("phone", e.target.value))} /></div>
                    <div>姓名<input type="text" value={state.user.nickname} onChange={(e) => dispatch(actions.changeUser("nickname", e.target.value))} /></div>
                    <div>密码<input type="text" value={state.user.password} onChange={(e) => dispatch(actions.changeUser("password", e.target.value))} /></div>
                    <div><button onClick={()=>{req()}}>注 册</button></div>
                </div>
            </div>
        </div>
    )
}
